<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/24 0024
 * Time: 上午 7:16
 */

namespace App\Http\Controllers\Admin;


use App\Model\Facades\AdminMenus;

class MenuCtrl extends CommonCtrl
{
    public function create()
    {
        $data['query'] = AdminMenus::create()->getToTree();
        return $this->responseView('create', $data);
    }

    public function store()
    {
        list($error, $info) = AdminMenus::create()->add();
        if (is_object($info))
            if (request()->ajax())
                return $this->error($error);
            else
                return back()->withErrors($info)->withInput();

        return $error ? $this->success('添加成功') : $this->error('添加失败');
    }

    public function edit($id)
    {
        $data['query'] = AdminMenus::create()->getToTree();
        $data['info'] = AdminMenus::create()->show($id);
        return $this->responseView('edit', $data);
    }

    public function renovate($id)
    {
        list($error, $info) = AdminMenus::create()->edit($id);
        if (is_object($info))
            if (request()->ajax())
                return $this->error($error);
            else
                return back()->withErrors($info)->withInput();

        return $error ? $this->success('添加成功') : $this->error('添加失败');
    }
}